package yawning.mew.gui.listener;

import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * This listener will manage the Display/Hide status on the toggle button.
 */
public class ToggleButtonListener implements ChangeListener {
	JPanel panel;
	String textWhenPressed;
	String textWhenDepressed;
	
	public ToggleButtonListener(JPanel target, String textWhenPressed, String textWhenDepressed) {
		panel = target;
		this.textWhenDepressed = textWhenDepressed;
		this.textWhenPressed = textWhenPressed;
	}
	
	@Override
	public void stateChanged(ChangeEvent e) {
		AbstractButton button = (AbstractButton) e.getSource();
		ButtonModel model = button.getModel();
		
		if(model.isSelected())
		{
			panel.setVisible(true);
			button.setText(textWhenPressed);
		}else
		{
			panel.setVisible(false);
			button.setText(textWhenDepressed);
		}
		
	}

}
